//
//  ParkingAnnotationView.m
//  CarLife
//
//  Created by yu on 2017/11/6.
//  Copyright © 2017年 jpas. All rights reserved.
//

#import "SearchAnnotationView.h"

@implementation SearchAnnotationView

- (id)initWithAnnotation:(id<MAAnnotation>)annotation reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithAnnotation:annotation reuseIdentifier:reuseIdentifier];
    if (self)
    {
        self.image = IMAGE_NAMED(@"near_position_nor");
    }
    return self;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    
    if (self.selected == selected) {
        return;
    }
    
    if (selected) {
        self.image = IMAGE_NAMED(@"near_position_sel");
        self.centerOffset = CGPointMake(0, -25);
        [self centerAnnotationAnimimate];
    } else {
        self.image = IMAGE_NAMED(@"near_position_nor");
        self.centerOffset = CGPointMake(0, 0);
    }
    
    [super setSelected:selected animated:animated];
}

- (void)centerAnnotationAnimimate
{
    [UIView animateWithDuration:0.5
                          delay:0
                        options:UIViewAnimationOptionCurveEaseOut
                     animations:^{
                         CGPoint center = self.center;
                         center.y -= 30;
                         [self setCenter:center];}
                     completion:nil];
    
    [UIView animateWithDuration:0.45
                          delay:0
                        options:UIViewAnimationOptionCurveEaseIn
                     animations:^{
                         CGPoint center = self.center;
                         center.y += 30;
                         [self setCenter:center];}
                     completion:nil];
}


@end
